package com.hongdee.scm.chooseCompany.controller;

import com.hongdee.scm.chooseCompany.service.ITScmChooseCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/15.
 */
@RestController
@RequestMapping("/scm/chooseCompany")
public class TScmChooseCompanyController {

    @Autowired
    private ITScmChooseCompanyService itScmChooseCompanyService;

    /**
     * 获取品牌
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/getBrand")
    @ResponseBody
    public List<Map> getBrand(@RequestParam(name = "uid", defaultValue = "") String uid,
                              @RequestParam(name = "token", defaultValue = "") String token)
    throws Exception{

        return this.itScmChooseCompanyService.getBrand();
    }

    /**
     * 获取品牌
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/getBrands")
    @ResponseBody
    public Map getBrands(@RequestParam(name = "uid", defaultValue = "") String uid,
                              @RequestParam(name = "token", defaultValue = "") String token)
            throws Exception{

        List list = this.itScmChooseCompanyService.getBrandAll(uid);
        Map map = new HashMap();
        map.put("success",true);
        map.put("msg","查询成功");
        map.put("dataList",list);
        return map;
    }

    /**
     * 获取区域
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/getPlace")
    @ResponseBody
    public List<Map> getPlace(@RequestParam(name = "uid", defaultValue = "") String uid,
                              @RequestParam(name = "token", defaultValue = "") String token)
    throws Exception{

        return this.itScmChooseCompanyService.getPlace();
    }

    /**
     * 获取公司
     * @param uid
     * @param token
     * @param type
     * @param code
     * @return
     * @throws Exception
     */
    @RequestMapping("/getCompany")
    @ResponseBody
    public Map getCompany(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "type", defaultValue = "") String type,
                          @RequestParam(name = "isInvoicing", defaultValue = "") String isInvoicing,
                          @RequestBody String[] code)
    throws Exception{
        Map map =new HashMap();

        List<Map<String,Object>> mapList = this.itScmChooseCompanyService.getCompanyByBrandOrPlace(type,code,uid,isInvoicing);
        map.put("success", true);
        map.put("msg", "公司查询成功！");
        map.put("dataList",mapList);
        return map;
    }

    /**
     * 根据Id查询公司
     * @param uid
     * @param token
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/getCompanyName")
    @ResponseBody
   public List<Map> getCompanyName(@RequestParam(name = "uid", defaultValue = "") String uid,
                                   @RequestParam(name = "token", defaultValue = "") String token,
                                   @RequestBody String[] companyId)
   throws Exception{
        return this.itScmChooseCompanyService.getCompanyName(companyId);
   }

}
